/**
 * 
 */
package soa.security.domain;

import org.springframework.ldap.odm.annotations.*;
import org.springframework.ldap.support.LdapNameBuilder;
import soa.security.Constants;

import javax.naming.Name;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author CreGu
 *
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
@Entry(objectClasses = { "zjtzsw-person", "zjtzsw-uid" })
public final class Person extends SoaUid {

	private static final long serialVersionUID = -6052240517163828525L;

	@XmlTransient
	@Id
	private Name dn;

	@DnAttribute(value = "uid")
	private String uid;

	@Attribute(name = "cname")
	private String name;

	private String ename;

	private int official = 1;
	
	@Deprecated
	private String officialType;

	private String IDType;

	private String IDNumber;

	private String caId;

	private String email;

	private String sex;

	private String birthday;

	@Attribute(name = "c")
	private String country;

	private String province;

	private String city;

	private String officeAddress;

	@Attribute(name = "telephoneNumber")
	private String officePhone;

	private String officeFax;

	private String homePhone;

	private String homeAddress;

	private String mobile;

	private int priority;

	private String createTime;

	/**
	 * 社保卡
	 */
	private String socialSecurityCard;

	/**
	 * 工商登记证
	 */
	private String businessRegistrationCertificate;

	@Transient
	private String departmentId;
	@XmlTransient
	@Transient
	private String departmentName;
	@XmlTransient
	@Transient
	private String positionName;
	@XmlTransient
	@Transient
	private String groupName;
	@XmlTransient
	@Transient
	private String roleName;

	@Transient
	private String orId;

	@Transient
	private String accountId;

	public Person() {
	}

	public Person(String uid, String name) {
		super();
		this.uid = uid;
		this.name = name;
	}
	
	public Person(String uid, String name, String mobile, String email) {
		super();
		this.uid = uid;
		this.name = name;
		this.mobile = mobile;
		this.email = email;
	}

	public static Person build(String uid, String name) {
		return new Person(uid, name);
	}
	
	public static Person build(String uid, String name, String mobile, String email) {
		return new Person(uid, name, mobile, email);
	}

	public Name buildDn(Name baseDn) {
		return LdapNameBuilder.newInstance(baseDn).add(Constants.UID, getUid())
				.build();
	}

	public Name getDn() {
		return dn;
	}

	public void setDn(Name dn) {
		this.dn = dn;
	}

	public String getUid() {
		return uid;
	}

	public void setUid(String uid) {
		this.uid = uid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEname() {
		return ename;
	}

	public void setEname(String ename) {
		this.ename = ename;
	}

	public int getOfficial() {
		return official;
	}

	public void setOfficial(int official) {
		this.official = official;
	}

	public String getOfficialType() {
		return officialType;
	}

	public void setOfficialType(String officialType) {
		this.officialType = officialType;
	}

	public String getIDType() {
		return IDType;
	}

	public void setIDType(String iDType) {
		IDType = iDType;
	}

	public String getIDNumber() {
		return IDNumber;
	}

	public void setIDNumber(String iDNumber) {
		IDNumber = iDNumber;
	}

	public String getCaId() {
		return caId;
	}

	public void setCaId(String caId) {
		this.caId = caId;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	public String getBirthday() {
		return birthday;
	}

	public void setBirthday(String birthday) {
		this.birthday = birthday;
	}

	public String getCountry() {
		return country;
	}

	public void setCountry(String country) {
		this.country = country;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getOfficeAddress() {
		return officeAddress;
	}

	public void setOfficeAddress(String officeAddress) {
		this.officeAddress = officeAddress;
	}

	public String getOfficePhone() {
		return officePhone;
	}

	public void setOfficePhone(String officePhone) {
		this.officePhone = officePhone;
	}

	public String getOfficeFax() {
		return officeFax;
	}

	public void setOfficeFax(String officeFax) {
		this.officeFax = officeFax;
	}

	public String getHomePhone() {
		return homePhone;
	}

	public void setHomePhone(String homePhone) {
		this.homePhone = homePhone;
	}

	public String getHomeAddress() {
		return homeAddress;
	}

	public void setHomeAddress(String homeAddress) {
		this.homeAddress = homeAddress;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public String getCreateTime() {
		return createTime;
	}

	public void setCreateTime(String createTime) {
		this.createTime = createTime;
	}

	public String getDepartmentName() {
		return departmentName;
	}

	public void setDepartmentName(String departmentName) {
		this.departmentName = departmentName;
	}

	public String getDepartmentId() {
		return departmentId;
	}

	public void setDepartmentId(String departmentId) {
		this.departmentId = departmentId;
	}

	public String getPositionName() {
		return positionName;
	}

	public void setPositionName(String positionName) {
		this.positionName = positionName;
	}

	public String getGroupName() {
		return groupName;
	}

	public void setGroupName(String groupName) {
		this.groupName = groupName;
	}

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getSocialSecurityCard() {
		return socialSecurityCard;
	}

	public void setSocialSecurityCard(String socialSecurityCard) {
		this.socialSecurityCard = socialSecurityCard;
	}

	public String getBusinessRegistrationCertificate() {
		return businessRegistrationCertificate;
	}

	public void setBusinessRegistrationCertificate(String businessRegistrationCertificate) {
		this.businessRegistrationCertificate = businessRegistrationCertificate;
	}

	public String getOrId() {
		return orId;
	}

	public void setOrId(String orId) {
		this.orId = orId;
	}

	public String getAccountId() {
		return accountId;
	}

	public void setAccountId(String accountId) {
		this.accountId = accountId;
	}

	@Override
	public String toString() {
		return "person uid[" + this.getUid() + "]";
	}

	@XmlRootElement
	@XmlAccessorType(XmlAccessType.FIELD)
	public static class Persons {
		protected List<Person> person = new ArrayList<Person>();

		public List<Person> getPerson() {
			return this.person;
		}

		public void addPerson(Person person) {
			this.person.add(person);
		}

		public boolean addAll(Collection<? extends Person> c) {
			return person.addAll(c);
		}
	}

}
